package com.bdqn.demo02.logger;

import org.apache.log4j.Logger;

/**
 * ProxyATM
 *
 * @author LILIBO
 * @since 2022-09-27
 */
public class ProxyATM implements ATM {


    private Logger logger = Logger.getLogger(MemberATM.class);

    private ATM atm;

    public ProxyATM(ATM atm) {
        this.atm = atm;
    }

    /**
     * 转账
     *
     * @param accountFrom 转出账户
     * @param accountTo 转入账户
     * @param money 转多少钱
     * @return 是否成功
     */
    @Override
    public boolean transfer(Account accountFrom, Account accountTo, double money) {
        logger.debug("--【⑤ 环绕增强】");
        boolean transfer = false;
        try {
            logger.debug("【① 前置增强】准备转账");
            transfer = atm.transfer(accountFrom, accountTo, money); // 真实调用
            logger.debug("【② 后置增强】转账完成");
        } catch (Exception e) {
            logger.debug("【③ 异常增强】出现异常：" + e.getMessage());
        } finally {
            logger.debug("【④ 最终增强】");
            logger.debug("一定会执行的代码");
        }
        logger.debug("转账成功");
        return transfer;
    }

}
